<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>platform.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_labs_useragent_platform.js.html">platform.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2013 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Closure user agent platform detection.
<a name="line17"></a> * @see &lt;a href=&quot;http://www.useragentstring.com/&quot;&gt;User agent strings&lt;/a&gt;
<a name="line18"></a> * For more information on browser brand, rendering engine, or device see the
<a name="line19"></a> * other sub-namespaces in goog.labs.userAgent (browser, engine, and device
<a name="line20"></a> * respectively).
<a name="line21"></a> *
<a name="line22"></a> */
<a name="line23"></a>
<a name="line24"></a>goog.provide(&#39;goog.labs.userAgent.platform&#39;);
<a name="line25"></a>
<a name="line26"></a>goog.require(&#39;goog.labs.userAgent.util&#39;);
<a name="line27"></a>goog.require(&#39;goog.string&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * @return {boolean} Whether the platform is Android.
<a name="line32"></a> */
<a name="line33"></a>goog.labs.userAgent.platform.isAndroid = function() {
<a name="line34"></a>  return goog.labs.userAgent.util.matchUserAgent(&#39;Android&#39;);
<a name="line35"></a>};
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>/**
<a name="line39"></a> * @return {boolean} Whether the platform is iPod.
<a name="line40"></a> */
<a name="line41"></a>goog.labs.userAgent.platform.isIpod = function() {
<a name="line42"></a>  return goog.labs.userAgent.util.matchUserAgent(&#39;iPod&#39;);
<a name="line43"></a>};
<a name="line44"></a>
<a name="line45"></a>
<a name="line46"></a>/**
<a name="line47"></a> * @return {boolean} Whether the platform is iPhone.
<a name="line48"></a> */
<a name="line49"></a>goog.labs.userAgent.platform.isIphone = function() {
<a name="line50"></a>  return goog.labs.userAgent.util.matchUserAgent(&#39;iPhone&#39;) &amp;&amp;
<a name="line51"></a>      !goog.labs.userAgent.util.matchUserAgent(&#39;iPod&#39;);
<a name="line52"></a>};
<a name="line53"></a>
<a name="line54"></a>
<a name="line55"></a>/**
<a name="line56"></a> * @return {boolean} Whether the platform is iPad.
<a name="line57"></a> */
<a name="line58"></a>goog.labs.userAgent.platform.isIpad = function() {
<a name="line59"></a>  return goog.labs.userAgent.util.matchUserAgent(&#39;iPad&#39;);
<a name="line60"></a>};
<a name="line61"></a>
<a name="line62"></a>
<a name="line63"></a>/**
<a name="line64"></a> * @return {boolean} Whether the platform is iOS.
<a name="line65"></a> */
<a name="line66"></a>goog.labs.userAgent.platform.isIos = function() {
<a name="line67"></a>  return goog.labs.userAgent.platform.isIphone() ||
<a name="line68"></a>      goog.labs.userAgent.platform.isIpad() ||
<a name="line69"></a>      goog.labs.userAgent.platform.isIpod();
<a name="line70"></a>};
<a name="line71"></a>
<a name="line72"></a>
<a name="line73"></a>/**
<a name="line74"></a> * @return {boolean} Whether the platform is Mac.
<a name="line75"></a> */
<a name="line76"></a>goog.labs.userAgent.platform.isMacintosh = function() {
<a name="line77"></a>  return goog.labs.userAgent.util.matchUserAgent(&#39;Macintosh&#39;);
<a name="line78"></a>};
<a name="line79"></a>
<a name="line80"></a>
<a name="line81"></a>/**
<a name="line82"></a> * @return {boolean} Whether the platform is Linux.
<a name="line83"></a> */
<a name="line84"></a>goog.labs.userAgent.platform.isLinux = function() {
<a name="line85"></a>  return goog.labs.userAgent.util.matchUserAgent(&#39;Linux&#39;);
<a name="line86"></a>};
<a name="line87"></a>
<a name="line88"></a>
<a name="line89"></a>/**
<a name="line90"></a> * @return {boolean} Whether the platform is Windows.
<a name="line91"></a> */
<a name="line92"></a>goog.labs.userAgent.platform.isWindows = function() {
<a name="line93"></a>  return goog.labs.userAgent.util.matchUserAgent(&#39;Windows&#39;);
<a name="line94"></a>};
<a name="line95"></a>
<a name="line96"></a>
<a name="line97"></a>/**
<a name="line98"></a> * @return {boolean} Whether the platform is ChromeOS.
<a name="line99"></a> */
<a name="line100"></a>goog.labs.userAgent.platform.isChromeOS = function() {
<a name="line101"></a>  return goog.labs.userAgent.util.matchUserAgent(&#39;CrOS&#39;);
<a name="line102"></a>};
<a name="line103"></a>
<a name="line104"></a>
<a name="line105"></a>/**
<a name="line106"></a> * The version of the platform. We only determine the version for Windows,
<a name="line107"></a> * Mac, and Chrome OS. It doesn&#39;t make much sense on Linux. For Windows, we only
<a name="line108"></a> * look at the NT version. Non-NT-based versions (e.g. 95, 98, etc.) are given
<a name="line109"></a> * version 0.0.
<a name="line110"></a> *
<a name="line111"></a> * @return {string} The platform version or empty string if version cannot be
<a name="line112"></a> *     determined.
<a name="line113"></a> */
<a name="line114"></a>goog.labs.userAgent.platform.getVersion = function() {
<a name="line115"></a>  var userAgentString = goog.labs.userAgent.util.getUserAgent();
<a name="line116"></a>  var version = &#39;&#39;, re;
<a name="line117"></a>  if (goog.labs.userAgent.platform.isWindows()) {
<a name="line118"></a>    re = /Windows NT ([0-9.]+)/;
<a name="line119"></a>    var match = re.exec(userAgentString);
<a name="line120"></a>    if (match) {
<a name="line121"></a>      version = match[1];
<a name="line122"></a>    } else {
<a name="line123"></a>      version = &#39;0.0&#39;;
<a name="line124"></a>    }
<a name="line125"></a>  } else if (goog.labs.userAgent.platform.isIos()) {
<a name="line126"></a>    re = /(?:iPhone|iPod|iPad|CPU)\s+OS\s+(\S+)/;
<a name="line127"></a>    var match = re.exec(userAgentString);
<a name="line128"></a>    // Report the version as x.y.z and not x_y_z
<a name="line129"></a>    version = match &amp;&amp; match[1].replace(/_/g, &#39;.&#39;);
<a name="line130"></a>  } else if (goog.labs.userAgent.platform.isMacintosh()) {
<a name="line131"></a>    re = /Mac OS X ([0-9_.]+)/;
<a name="line132"></a>    var match = re.exec(userAgentString);
<a name="line133"></a>    // Note: some old versions of Camino do not report an OSX version.
<a name="line134"></a>    // Default to 10.
<a name="line135"></a>    version = match ? match[1].replace(/_/g, &#39;.&#39;) : &#39;10&#39;;
<a name="line136"></a>  } else if (goog.labs.userAgent.platform.isAndroid()) {
<a name="line137"></a>    re = /Android\s+([^\);]+)(\)|;)/;
<a name="line138"></a>    var match = re.exec(userAgentString);
<a name="line139"></a>    version = match &amp;&amp; match[1];
<a name="line140"></a>  } else if (goog.labs.userAgent.platform.isChromeOS()) {
<a name="line141"></a>    re = /(?:CrOS\s+(?:i686|x86_64)\s+([0-9.]+))/;
<a name="line142"></a>    var match = re.exec(userAgentString);
<a name="line143"></a>    version = match &amp;&amp; match[1];
<a name="line144"></a>  }
<a name="line145"></a>  return version || &#39;&#39;;
<a name="line146"></a>};
<a name="line147"></a>
<a name="line148"></a>
<a name="line149"></a>/**
<a name="line150"></a> * @param {string|number} version The version to check.
<a name="line151"></a> * @return {boolean} Whether the browser version is higher or the same as the
<a name="line152"></a> *     given version.
<a name="line153"></a> */
<a name="line154"></a>goog.labs.userAgent.platform.isVersionOrHigher = function(version) {
<a name="line155"></a>  return goog.string.compareVersions(goog.labs.userAgent.platform.getVersion(),
<a name="line156"></a>                                     version) &gt;= 0;
<a name="line157"></a>};
</pre>


</body>
</html>
